package com.example.demo3.web;

import com.example.demo3.domain.bo.PermissionBo;
import com.example.demo3.domain.vo.PermissionVo;
import com.example.demo3.service.PermissionsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("permission")
public class PermissionsController {


    private final PermissionsService permissionsService;


    @RequestMapping()
    public PageInfo<PermissionVo> list(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize, PermissionBo PermissionBo) {
        PageHelper.startPage(pageNum, pageSize);
        List<PermissionVo> permissionVoList = permissionsService.queryPermissionList(PermissionBo);
        return new PageInfo<>(permissionVoList);
    }


//    @RequiresPermissions("menu:add")
    @PostMapping()
    public String add(@Validated @RequestBody PermissionBo permissionBo) {
        Boolean flag = permissionsService.insertByBo(permissionBo);
        return "add success!";
    }



//    @RequiresPermissions("menu:edit")
    @PutMapping()
    public String edit(@RequestBody PermissionBo permissionBo) {
        Boolean flag =  permissionsService.updateByBo(permissionBo);

        return "admin edit success!";
    }

//    @RequiresPermissions("menu:remove")
    @DeleteMapping()
    public String remove(@RequestParam String [] ids) {
        Boolean flag =  permissionsService.deleteById(ids);
        return "delete success!";
    }











}
